package com.kgc.personprovider.controller;

import com.kgc.basic.util.ResponseMsg;
import com.kgc.personcommon.pojo.Role;
import com.kgc.personcommon.remote.RoleRemote;
import com.kgc.personprovider.service.RoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.Map;

@Controller
public class RoleController implements RoleRemote {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private RoleService roleService;

    @Override
    public ResponseMsg getRolePage(Map<String, Object> map) {
        logger.info("RoleController getRolePage map={}", map);
        ResponseMsg response = roleService.getByPage(map);
        logger.debug("roleService getByPage map={} → response={}", map, response);
        return response;
    }

    @Override
    public ResponseMsg addRole(Role role) {
        logger.info("RoleController addRole role={}", role);
        ResponseMsg response = roleService.add(role);
        logger.debug("roleService add role={} → response={}", role, response);
        return response;
    }

    @Override
    public ResponseMsg updateRole(Role role) {
        logger.info("RoleController updateRole role={}", role);
        ResponseMsg response = roleService.update(role);
        logger.debug("roleService update role={} → response={}", role, response);
        return response;
    }

    @Override
    public ResponseMsg delRole(String id) {
        logger.info("RoleController delRole id={}", id);
        ResponseMsg response = roleService.delete(id);
        logger.debug("roleService delete id={} → response={}", id, response);
        return response;
    }

    @Override
    public ResponseMsg getRoleById(String id) {
        logger.info("RoleController getRoleById id={}", id);
        ResponseMsg response = roleService.getById(id);
        logger.debug("roleService getById id={} → response={}", id, response);
        return response;
    }

    @Override
    public ResponseMsg getAllRole(Map<String, Object> map) {
        logger.info("RoleController getAllRole map={}", map);
        ResponseMsg response = roleService.getAll(map);
        logger.debug("roleService getAll map={} → response={}", map, response);
        return response;
    }
}
